﻿namespace Sage.MarkdownRenderer
{
    /// <summary>
    /// WebView 内容状态
    /// </summary>
    public class MarkdownViewContentState
    {
        /// <summary>
        /// 内容类型
        /// </summary>
        public ContentType Type { get; set; } = ContentType.Initial;

        /// <summary>
        /// Markdown 文本内容
        /// </summary>
        public string? MarkdownText { get; set; }

        /// <summary>
        /// 自定义内容的标题
        /// </summary>
        public string? CustomTitle { get; set; }

        /// <summary>
        /// 自定义内容的主体
        /// </summary>
        public string? CustomContent { get; set; }

        /// <summary>
        /// 空内容时的提示消息
        /// </summary>
        public string? EmptyMessage { get; set; }

        /// <summary>
        /// 初始页面的标题
        /// </summary>
        public string? InitialTitle { get; set; }

        /// <summary>
        /// 初始页面的内容
        /// </summary>
        public string? InitialContent { get; set; }

        /// <summary>
        /// 重置状态
        /// </summary>
        public void Reset()
        {
            Type = ContentType.Initial;
            MarkdownText = null;
            CustomTitle = null;
            CustomContent = null;
            EmptyMessage = null;
            InitialTitle = null;
            InitialContent = null;
        }

        /// <summary>
        /// 设置 Markdown 内容状态
        /// </summary>
        public void SetMarkdown(string markdownText)
        {
            Reset();
            Type = ContentType.Markdown;
            MarkdownText = markdownText;
        }

        /// <summary>
        /// 设置自定义内容状态
        /// </summary>
        public void SetCustomContent(string title, string content)
        {
            Reset();
            Type = ContentType.CustomContent;
            CustomTitle = title;
            CustomContent = content;
        }

        /// <summary>
        /// 设置空内容状态
        /// </summary>
        public void SetEmpty(string? message = null)
        {
            Reset();
            Type = ContentType.Empty;
            EmptyMessage = message;
        }

        /// <summary>
        /// 设置初始页面状态
        /// </summary>
        public void SetInitial(string? title = null, string? content = null)
        {
            Reset();
            Type = ContentType.Initial;
            InitialTitle = title;
            InitialContent = content;
        }

        /// <summary>
        /// 检查是否有有效内容
        /// </summary>
        public bool HasContent => Type switch
        {
            ContentType.Markdown => !string.IsNullOrEmpty(MarkdownText),
            ContentType.CustomContent => !string.IsNullOrEmpty(CustomContent),
            ContentType.Empty => true,
            ContentType.Initial => true,
            _ => false
        };
    }
}
